package com.chen.serviceverificationcode.controller;

import com.chen.internalcommon.dto.ResponseResult;
import com.chen.internalcommon.response.NumberCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenLiuPing
 **/
@RestController
public class NumberCodeController {

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size) {
        System.out.println("验证码长度：" + size);
        // 生成验证码
        double mathRandom = (Math.random()*9 + 1) * (Math.pow(10,size-1));
        int resultInt = (int)mathRandom;
        System.out.println("生成的验证码:"+resultInt);
        NumberCodeResponse numberCodeResponse = new NumberCodeResponse(resultInt);
        return ResponseResult.success(numberCodeResponse);
    }
}
